package com.superman.supermarket.client.composite.addrlist;

import java.util.Map;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.superman.mvpframe.client.gin.XGinjector;
import com.superman.supermarket.client.event.AddrChoosePageEvent;
import com.superman.supermarket.client.event.AddrChoosePageEvent.AddrChoosePageEventType;

/**
 * 地址选择模块
 * 
 * @author superman
 * @version 2018年8月10日下午11:02:00
 */
public class AddrChooseModule extends AddrListCellModule {

	private String addrId;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月10日 下午11:03:14
	 */
	public AddrChooseModule() {
		deleteicon.removeStyleName("fa-trash-o");
		deleteicon.addStyleName("fa-edit");

		deletehtml.setText("编辑");

		mainpanel.addDomHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				event.stopPropagation();
				XGinjector.INSTANCE.getEventbusController().fire(new AddrChoosePageEvent(addrId, AddrChoosePageEventType.SELECT));
			}
		}, ClickEvent.getType());

		deletepanel.addDomHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				event.stopPropagation();
				XGinjector.INSTANCE.getEventbusController().fire(new AddrChoosePageEvent(map, AddrChoosePageEventType.EDIT));
			}
		}, ClickEvent.getType());

	}

	/**
	 * 当前是否选中
	 * 
	 * @author superman
	 * @version 2018年8月10日 下午11:08:31
	 * @param select
	 */
	public void select(boolean select) {
		if (select) {
			defaulticon.addStyleName("fa-check-circle");
			setdefaulthtml.setText("当前使用");
		} else {
			setdefaultpanel.setVisible(false);
		}
	}

	@Override
	public void setData(Map<String, Object> map) {
		this.map = map;
		this.addrId = String.valueOf(map.get("ADDR_ID"));

		boolean isDefault = Double.parseDouble(String.valueOf(map.get("IS_DEFAULT"))) == 1;

		StringBuffer sb = new StringBuffer();
		if (isDefault)
			sb.append("<span style='color:#e31436;font-size:12px;line-height:2;'>[默认]</span>");
		sb.append(String.valueOf(map.get("RECEIVE_AREA")) + String.valueOf(map.get("RECEIVE_ADDR")));

		receivernamehtml.setText(String.valueOf(map.get("RECEIVER")));
		telhtml.setText(String.valueOf(map.get("PHONE_NO")));
		addrhtml.setHTML(sb.toString());

	}

}
